/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.math;

import java.math.BigInteger;
import java.text.MessageFormat;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/5/8
 */
public class Lession1_3 {

    public static String decimalToBinary(int decimalSource) {
        boolean isNav = decimalSource < 0;
        int temp = isNav ? -decimalSource : decimalSource;
        StringBuilder sb = new StringBuilder();
        while (temp != 0) {
            sb.append((temp & 1) == 0 ? 0 : 1);
            temp >>= 1;
        }
        if (isNav) {
            sb.append('-');
        }
        return sb.reverse().toString();
    }

    public static void main(String[] args) {
        System.out.println(3 ^ 3);
        System.out.println(3 ^ -3);
        System.out.println(4 ^ -4);
        System.out.println(7 ^ -7);
        System.out.println(9 ^ -9);
        System.out.println(10 ^ -10);
        System.out.println(11 ^ -11);
        System.out.println(12 ^ -12);
        System.out.println("-----------------");
        BigInteger bi = new BigInteger("3", 10);
        System.out.println(bi.toString(2));
        bi = new BigInteger("-3", 10);
        System.out.println(bi.toString(2));
        bi = new BigInteger("-2", 10);
        System.out.println(bi.toString(2));
        System.out.println("-----------------");
        System.out.println(5 ^ 3);
        System.out.println("-----------");
        System.out.println(decimalToBinary(5));
        System.out.println(decimalToBinary(15));
        System.out.println(decimalToBinary(-5));
        System.out.println(decimalToBinary(17));
        System.out.println("-----------");
        int x = 1;
        int y = 2;
        x = x ^ y;
        y = x ^ y;
        x = x ^ y;
        System.out.println(MessageFormat.format("x:{0}, y:{1}", x, y));
    }
}
